package com.app.bimo.commonbusiness.util;

import com.app.bimo.commonbusiness.mvp.IView;
import com.uber.autodispose.AutoDispose;
import com.uber.autodispose.AutoDisposeConverter;
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;

public class RxLifecycleUtils {
    private RxLifecycleUtils() {
        throw new IllegalStateException("Can't instance the RxLifecycleUtils");
    }

    public static <T> CustomAutoDisposeConverter<T> bindCustomLifecycle(LifecycleOwner lifecycleOwner, IView iView,boolean isPageLoading,boolean isLoading) {
        AutoDisposeConverter<T> autoDisposeConverter=AutoDispose.autoDisposable(
                AndroidLifecycleScopeProvider.from(lifecycleOwner));
        CustomAutoDisposeConverter<T> customAutoDisposeConverter=new CustomAutoDisposeConverter(autoDisposeConverter,iView);
        customAutoDisposeConverter.setPageLoading(isPageLoading);
        customAutoDisposeConverter.setShowLoading(isLoading);
        return customAutoDisposeConverter;
    }

    public static <T> AutoDisposeConverter<T> bindLifecycle(LifecycleOwner lifecycleOwner) {
        return AutoDispose.autoDisposable(
                AndroidLifecycleScopeProvider.from(lifecycleOwner));
    }

    public static <T> AutoDisposeConverter<T> bindLifecycle(Lifecycle lifecycle) {
        return AutoDispose.autoDisposable(
                AndroidLifecycleScopeProvider.from(lifecycle));
    }
}
